
#ifndef TCPClient_h__
#define TCPClient_h__

#include "IObject/ITCPClient.h"
#include "ClientSession.h"
#include <boost/thread/shared_mutex.hpp>
#include <boost/thread.hpp>

class TCPClient : public ITCPClient
{
public:
	TCPClient();
	virtual ~TCPClient();

public:
	virtual CONNECT_STATUS Connect(SocketID id, std::string ip, unsigned short port,
		IPacketCodec *pCodec,
		const MessageHandler & handler);

	virtual void Close(SocketID id);

	virtual SendResult AsyncSend(SocketID id, const char *pBuffer, int size) ;
	virtual SendResult SyncSend(SocketID id, const char *pBuffer, int size);

public:
	void check_socket(int expired_time);

private:
	boost::shared_mutex m_mutex;
	std::map<SocketID, boost::shared_ptr<ClientSession> > m_mapSessions;
	
	boost::asio::io_service m_socket_io;
	boost::asio::io_service::work m_socket_io_work;
	boost::thread			m_thread;
};

#endif // TCPClient_h__

